package com.alog.yzd.bookmall.web.filter;

import com.alog.yzd.bookmall.domain.admin.admin.Admin;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Auther: Ye Zhengdong
 * @Date: 2019/1/12 21:41
 * @Description:
 */
public class AdminLoginFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest)request;
        Admin admin = (Admin) req.getSession().getAttribute("admin");
        if(admin == null){
            req.setAttribute("msg", "您还没有登陆, 请登陆");
            req.getRequestDispatcher("/adminjsps/login.jsp").forward(request, response);
        } else {
            chain.doFilter(request, response);
        }

    }

    @Override
    public void destroy() {

    }
}
